package com.qk;

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.RedisTemplate;

import java.util.List;
import java.util.Set;
import java.util.concurrent.TimeUnit;

@SpringBootTest
public class RedisTet {

    @Autowired
    private RedisTemplate<Object, Object> redisTemplate;

    @Test
    public void test(){
        //存
        redisTemplate.opsForValue().set("name","小黑");
        //取
        Object name = redisTemplate.opsForValue().get("name");
        System.out.println(name);
        //设置存放时间
        redisTemplate.opsForValue().set("age",18,30, TimeUnit.SECONDS);
        Object name1 = redisTemplate.opsForValue().get("age");
        System.out.println(name1);
    }


    @Test
    public void test2(){
        //存 List
        redisTemplate.opsForList().leftPushAll("dog", "小黑","小黄","小白");
        //取 List
        List<Object> dog = redisTemplate.opsForList().range("dog", 0, -1);
        System.out.println(dog);

        redisTemplate.opsForList().rightPushAll("dog", "小灰","大黄","小花");

        List<Object> dog1 = redisTemplate.opsForList().range("dog", 0, -1);
        System.out.println(dog1);

        Object dog2 = redisTemplate.opsForList().leftPop("dog");
        System.out.println(dog2);
    }

    @Test
    public void test3(){
        //存 Set
        redisTemplate.opsForSet().add("cat","小黑","小黄","小白");
        //取 Set
        Object cat = redisTemplate.opsForSet().members("cat");
        System.out.println(cat);

    }
}
